package com.hspedu.seckill.rabbitmq;

import com.hspedu.seckill.config.RabbitMQConfig;
import com.hspedu.seckill.config.RabbitMQHeadersConfig;
import com.hspedu.seckill.config.RabbitMQTopicConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: xujiabing
 * @date: 2024-11-24 17:53
 * @description: 消息接收者/消费者
 */
@Service
@Slf4j
public class MQReceiver {

    /**
     * 监听队列 queue
     * @param msg
     */
    @RabbitListener(queues = RabbitMQConfig.QUEUE)
    public void receive(Object msg) {
        log.info("接收到消息 = {} " , msg);
    }

    /**
     * 监听队列 queue_fanout01
     * @param msg
     */
    @RabbitListener(queues = RabbitMQConfig.QUEUE1)
    public void receive1(Object msg) {
        log.info("从队列queue_fanout01 接收到消息 = {} " , msg);
    }

    /**
     * 监听队列 queue_fanout02
     * @param msg
     */
    @RabbitListener(queues = RabbitMQConfig.QUEUE2)
    public void receive2(Object msg) {
        log.info("从队列queue_fanout02 接收到消息 = {} " , msg);
    }

    /**
     * 监听队列 queue_direct01
     * @param msg
     */
    @RabbitListener(queues = RabbitMQConfig.QUEUE_DIRECT1)
    public void queue_direct1(Object msg) {
        log.info("从queue_direct01 接收消息-" + msg);
    }

    /**
     * 监听队列 queue_direct02
     * @param msg
     */
    @RabbitListener(queues = RabbitMQConfig.QUEUE_DIRECT2)
    public void queue_direct2(Object msg) {
        log.info("从queue_direct02 接收消息-" + msg);
    }

    /**
     * 监听队列 queue_topic01
     * @param msg
     */
    @RabbitListener(queues = RabbitMQTopicConfig.QUEUE01)
    public void queue_topic01(Object msg) {
        log.info("从queue_topic01 接收消息-" + msg);
    }

    /**
     * 监听队列 queue_topic02
     * @param msg
     */
    @RabbitListener(queues = RabbitMQTopicConfig.QUEUE02)
    public void queue_topic02(Object msg) {
        log.info("从queue_topic02 接收消息-" + msg);
    }

    /**
     * 监听队列 queue_header01
     * @param message
     */
    @RabbitListener(queues = RabbitMQHeadersConfig.QUEUE01)
    public void queue_header01(Message message) {
        log.info("queue_header01 接收消息message 对象" + message);
        log.info("queue_header01 接收消息" + new String(message.getBody()));
    }

    /**
     * 监听队列queue_header02
     * @param message
     */
    @RabbitListener(queues = RabbitMQHeadersConfig.QUEUE02)
    public void queue_header02(Message message) {
        log.info("queue_header02 接收消息message 对象" + message);
        log.info("queue_header02 接收消息" + new String(message.getBody()));
    }
}
